// bflat minimal runtime library
// Copyright (C) 2021-2022 Michal Strehovsky
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

namespace System.Runtime.CompilerServices
{
    public static unsafe partial class Unsafe
    {
        // The body of this method is generated by the compiler.
        // It will do what Unsafe.Add is expected to do. It's just not possible to express it in C#.
        [Intrinsic]
        public static extern ref T Add<T>(ref T source, int elementOffset);
        [Intrinsic]
        public static extern ref T Add<T>(ref T source, IntPtr elementOffset);
        [Intrinsic]
        public static extern ref TTo As<TFrom, TTo>(ref TFrom source);
        [Intrinsic]
        public static extern T As<T>(object o) where T : class;
        [Intrinsic]
        public static extern void* AsPointer<T>(ref T value);
        [Intrinsic]
        public static extern ref T AsRef<T>(void* source);
        [Intrinsic]
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static extern IntPtr ByteOffset<T>(ref readonly T origin, ref readonly T target);
    }
}
